<%
accordion_id = SecureRandom.hex 
%>

<% content_for :pre_content do %>
    <dl class="accordion" data-accordion>
      <dd class="accordion-top-navigation">
        <a href="#panel_filters">Filters</a>
        <div id="panel_filters" class="panel content">
            <%= form_tag render_metadata_partial_result_path(id: @result.id, partial: "scan_metadata", target: "#partial_#{accordion_id}"), :data=>{target: "#partial_#{accordion_id}"}, :class=>"facets", :remote=>true do |f| %>
                <% facets = ["source"] %>
                <% facets.each do |f| %>
                    <%= label_tag do %><%= f.titleize %>
                      <%= collection_select "filter",f, @result.metadata["scan_metadata"].map{|v| v[f].class == Array ? v[f].flatten : v[f].to_s}.flatten.reject{|x| x.blank? || x.class == Hash}.uniq , :to_s, :titleize , {:selected => (defined?(selected_facets) ? selected_facets : {}).try(:[],f)}, {class: "select2",:multiple=>true} %>
                      <%= hidden_field_tag "filter_on[#{f}]", "scan_metadata" %>
                    <% end %>
                <% end %>
            <% end %>
        </div>
      </dd>
    </dl>

<% end %>


<%= render partial: "shared/ajax_metadata_accordion", locals: {result: @result, title: "Scans", partial_name: "scan_metadata", options: {accordion_id: accordion_id, include_refresh: true}} %>


